//
//  LFBusinessController.m
//  ServiceBaZhou
//
//  Created by 刘江涛 on 2017/8/24.
//  Copyright © 2017年 weierda. All rights reserved.
//

#import "LFBusinessController.h"

#import "BussinessModel.h"

#import "CFToolUtil.h"

@interface LFBusinessController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) NSMutableArray *dataArray;

@end

@implementation LFBusinessController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createNavigation:@"融资信息"];
    
    [self createTableView];
    
    [self loadData];
}

- (void)createTableView{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, Width, Height-64) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
}

- (void)loadData{
    NSMutableDictionary *para = [NSMutableDictionary dictionaryWithCapacity:0];
    [para setObject:Token forKey:@"key"];
    [para setObject:_keyNo forKey:@"searchKey"];
    
    [CFHttpTools getRequest:@"BusinessStateV4/SearchCompanyFinancings" params:para success:^(id responseObj) {
        //
        CFLog(@"%@",responseObj);
        
        NSArray *bussinessArray = responseObj[@"Result"];
        
        JSONModelArray *modelArray = [[JSONModelArray alloc]initWithArray:bussinessArray modelClass:[BussinessModel class]];
        
        self.dataArray = [NSMutableArray array];
        
        [self.dataArray addObjectsFromArray:(NSArray *)modelArray];
        
        [_tableView reloadData];
        
    } failure:^(NSError *error) {
        //
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    BussinessModel *model = _dataArray[indexPath.row];
    return 50 + [CFToolUtil getLabelHeightWith:model.Investment AndStrSize:13 AndLabelWith:Width - 60];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *iden = @"iden";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:iden];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    BussinessModel *model = _dataArray[indexPath.row];
    
    cell.textLabel.text = [NSString stringWithFormat:@"%@  %@ | %@",[model.Date substringToIndex:10],model.Amount,model.Round];
    cell.textLabel.font = [UIFont systemFontOfSize:13.0];
    cell.detailTextLabel.text = model.Investment;
    cell.detailTextLabel.textColor = [UIColor colorWithHexString:@"#A1A1A1"];
    cell.detailTextLabel.numberOfLines = 0;
    
    return cell;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
